import junit.framework.TestCase;


public class TestNetwork extends TestCase {

	private Network testNet = new Network();
	private Position pos1 = new Position(1,1);
	private Node node1 = new Node(pos1);
	
	/**
	 * test that it's possible to make a network with a 50*50 matrix with one
	 * node in each square and that there exists 4 query nodes. 
	 * This test requires that QueryNodes is public.
	 */
	public void testNetwork() {
		int i;
		assertNotNull(testNet.network);
		assertEquals(10000,testNet.MaxJumps);
		
		for(i=0;i<4;i++){
			Node oneQueryNode = testNet.QueryNodes.get(i);
			assertTrue(testNet.network.containsValue(oneQueryNode));
		}
	
	}
	/**
	 * Test that it's possible to add one event to networks eventList.
	 */
	public void testAddEvent() {
		
		Event theHappening = new Event(testNet,node1);
		testNet.addEvent(theHappening);
		assertEquals(1,testNet.EventList.size());
	}
	/**
	 * Test that it's possible to add one Agent to networks agentList. This 
	 * requires that AgentList is public.
	 */
	public void testAddAgent() {
		Network net1 = new Network();
		Agent agent007 = new Agent(node1,net1);
		testNet.addAgent(agent007);
		assertEquals(1,net1.AgentList.size());
	}
	/**
	 * Test that it's possible to add one Query to networks queryList.
	 */
	public void testAddQuery(){
		
		while(testNet.EventList.isEmpty()){
			node1.generateEvent(testNet);
		}
		Query query1 = new Query(node1,testNet);
		testNet.addQuery(query1);
		assertEquals(1,testNet.QueryList.size());
	}
	/**
	 * Test that it's possible to remove one Agent from networks AgentList.
	 * This requires that AgentList is public.
	 */
	public void testRemoveAgent() {
		
		Network net2 = new Network();
		Agent agent007 = new Agent(node1,net2);
		testNet.addAgent(agent007);
		assertEquals(1,testNet.AgentList.size());
		
		testNet.removeAgent(agent007);
		assertEquals(0,testNet.AgentList.size());
		
	}
	/**
	 * Test that it's possible to remove a query from networks queryList.
	 */
	public void testRemoveQuery() {
		
		while(testNet.EventList.isEmpty()){
			node1.generateEvent(testNet);
		}
		Query query1 = new Query(node1,testNet);
		testNet.addQuery(query1);
		assertEquals(1,testNet.QueryList.size());
		
		testNet.removeQuery(query1);
		assertEquals(0,testNet.QueryList.size());
		
	}
	/**
	 * Test that it's possible to add a query to the ResendQuery list.
	 * This requires that ResendQuery is public.
	 */
	public void testAddResend() {
		
		while(testNet.EventList.isEmpty()){
			node1.generateEvent(testNet);
		}
		Query query2 = new Query(node1,testNet);
		testNet.addResend(query2);
		assertEquals(1,testNet.ResendQuery.size());
	}

}
